import {fabric} from "@/js/fabric"
import ShDevice from "./suoheng.device";
const loadlist ={
    circle(item){
        return new fabric.Circle(item)
    },
    path(item){
        return new fabric.Path(item.path,item)
    },
    rect(item){
        return new fabric.Rect(item)
    },
    line(item){
        return new fabric.Line([item.x1,item.y1,item.x2,item.y2],item)
    },
    point(item){
        return new fabric.Circle(item)
    },
    polygon(item){
       return new fabric.Polygon(item._drawPolygonPoints, item)
    },
    polyline(item){
        return new fabric.Polyline(item._drawPolygonPoints, item)
    }
}
let devicelist ={}
function createdevice(obj){
    var list = [];
    obj.objects.forEach(item => {
      list.push(loadlist[item.type](item));
    });
   devicelist[obj.name]= new ShDevice(list, {
        centeredScaling: true, //中心缩放
        attr:obj.attr,
        name:obj.name,
    });
    devicelist[obj.name].src=devicelist[obj.name].toDataURL({
        format: 'png'
    });
    return devicelist[obj.name]
}
function createdevice1(obj){
    var list = [];
    let device;
    obj.objects.forEach(item => {
      list.push(loadlist[item.type](item));
    });
    device= new ShDevice(list, {
        centeredScaling: true, //中心缩放
        attr:obj.attr,
        name:obj.name,
    });
    device.src=device.toDataURL({
        format: 'png'
    });
    return device
}
 function deviceloader(list){
     list.forEach(( element,index)=>{
        createdevice(element.default||element) 
    });
    return devicelist
}   
export {loadlist,deviceloader,devicelist,createdevice,createdevice1}
